package com.huawei.appmarket.service.thirdzone;

import android.app.ActionBar;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.huawei.android.app.ActionBarEx;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.RemoteBuoyAction;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.store.bean.detail.DetailResponse;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSSelector;
import com.huawei.appgallery.foundation.ui.css.CSSStyleSheet;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.Layout;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.e;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appmarket.framework.widget.CustomActionBar;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHeadBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.view.AppDetailFragmentProtocol;
import com.huawei.appmarket.service.appdetail.view.AppDetailFragmentProtocol.Request;
import com.huawei.secure.android.common.intent.SafeBundle;
import java.util.LinkedHashMap;
import java.util.List;
import o.ayw;
import o.ayy;
import o.azb;
import o.azc;
import o.cfv;
import o.cgv;
import o.cin;
import o.cir;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cvt;
import o.cwv;
import o.dgh;
import o.dgm;
import o.dhr;
import o.djf;
import o.djt;
import o.Logger;
import o.dof;
import o.drr;
import o.drt;
import o.dvq;
import o.eib;
import o.ejz;
import o.epr;
import o.epw;
import o.CollectCheck;
import o.evd;
import o.evx;
import o.ewm;
import o.ewm.c;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.FragmentTransaction;

public class ThirdAppZoneActivity extends FragmentActivity implements e, dhr, djt {
    private int ʻॱ = -1;
    private BroadcastReceiver ʼॱ = new BroadcastReceiver(this) {
        final /* synthetic */ ThirdAppZoneActivity ˊ;
        String ˎ = "homekey";
        String ˏ = "reason";

        {
            this.ˊ = r2;
        }

        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action == null || !action.equals("android.intent.action.CLOSE_SYSTEM_DIALOGS")) {
                int intExtra = intent.getIntExtra("downloadtask.status", -1);
                SessionDownloadTask ˊ = SessionDownloadTask.ˊ(intent.getBundleExtra("downloadtask.all"));
                if (ˊ != null && intExtra >= 0 && intExtra <= 8 && intExtra != 2) {
                    ejz.ˏ(context, this.ˊ.ˋॱ, intExtra, ˊ.ˊˊ());
                }
            } else if (TextUtils.equals(intent.getStringExtra(this.ˏ), this.ˎ)) {
                this.ˊ.ॱˊ();
            }
        }
    };
    private int ʽॱ = -1;
    private int ʾ = 0;
    private int ʿ;
    private int ˈ;
    private String ˊॱ = null;
    private String ˋॱ = "";
    String ˏॱ;
    private String ͺ = "";
    private boolean ॱˊ = false;
    private CustomActionBar ॱˋ;
    private ActionBar ॱˎ;
    private View ॱᐝ;
    private TextView ᐝॱ;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ayy.ˋ().ˎ(getWindow());
        ayw.ॱ((Activity) this);
        eib.ॱ((Context) this);
        setContentView(h.ˊꜞ);
        cgv.ˋ(this, c.ˎ, c.ॱˎ);
        if (bundle != null) {
            this.ʻॱ = bundle.getInt("AppDetailActivity.isimmer", -1);
            this.ʿ = bundle.getInt("AppDetailActivity.scrolly", 1);
            this.ʽॱ = bundle.getInt("AppDetailActivity.headheight", -1);
            this.ˈ = bundle.getInt("AppDetailActivity.bgcolor", getResources().getColor(c.ॱˎ));
            this.ʾ = bundle.getInt("AppDetailActivity.contenttype", 0);
        }
        ʼ();
        if (!(this.ॱˋ == null || this.ʽॱ == -1)) {
            this.ॱˋ.setBgColor(this.ˈ);
            ˋ(this.ʿ, this.ʽॱ);
            if (this.ʾ != 3) {
                ˋ(this.ʿ, this.ʽॱ);
            }
        }
        getActionBar().setDisplayOptions(4, 4);
        getActionBar().setTitle(getString(n.ॱـ));
        Intent intent = getIntent();
        if (intent != null) {
            try {
                this.ˊॱ = intent.getStringExtra("ThirdAppZoneActivity.Card.URI");
                if (bundle != null) {
                    String string = bundle.getString("ThirdAppZoneActivity.Card.ThirdId");
                    if (!(string == null || dof.ॱ(string))) {
                        epr.ˎ().ˎ(string);
                    }
                }
            } catch (Exception e) {
                Logger.e("ThirdAppZoneActivity", "onCreate(Bundle savedInstanceState) " + e.toString());
            }
            if (this.ˊॱ != null) {
                Bundle bundle2 = new Bundle();
                bundle2.putString(RemoteBuoyAction.REMOTE_BUOY_URI, this.ˊॱ);
                Fragment ˊ = cjk.ˎ().ˊ(new cjm("loading.fragment", null));
                if (ˊ instanceof TaskFragment) {
                    TaskFragment taskFragment = (TaskFragment) ˊ;
                    taskFragment.ʼ(bundle2);
                    taskFragment.ˋ(ˏॱ(), j.ˋˊ, "TaskFragment");
                    return;
                }
                return;
            }
            finish();
            return;
        }
        finish();
    }

    private void ˋ(DetailResponse<?> detailResponse) {
        View findViewById = findViewById(j.ᐝˑ);
        if (detailResponse.ʾ() == 1) {
            OnClickListener anonymousClass2 = new OnClickListener(this) {
                final /* synthetic */ ThirdAppZoneActivity ˏ;

                {
                    this.ˏ = r1;
                }

                public void onClick(View view) {
                    djf.ˋ(this.ˏ, "", null);
                }
            };
            if (azc.ˎ().ॱ() >= 17 && this.ʾ != 3) {
                ActionBarEx.setEndIcon(getActionBar(), true, getResources().getDrawable(ewm.e.ˋʼ), anonymousClass2);
                return;
            } else if (findViewById != null) {
                findViewById.setVisibility(0);
                findViewById.setOnClickListener(anonymousClass2);
                return;
            } else {
                return;
            }
        }
        findViewById.setVisibility(8);
        if (this.ॱˋ != null) {
            this.ॱˋ.setSearchIconVisible(8);
        }
    }

    private void ʼ() {
        this.ॱᐝ = findViewById(j.ˇˊ);
        azb.ˏ(this.ॱᐝ);
        this.ᐝॱ = (TextView) findViewById(j.ᐝㆍ);
        ᐝ();
        ॱॱ();
        this.ॱˎ = getActionBar();
        this.ॱˋ = (CustomActionBar) findViewById(j.ˊˈ);
        ˏ(this.ʻॱ);
    }

    private void ॱॱ() {
        findViewById(j.ᐝˑ).setOnClickListener(new evx(this) {
            final /* synthetic */ ThirdAppZoneActivity ˊ;

            {
                this.ˊ = r1;
            }

            public void ˋ(View view) {
                this.ˊ.ʼॱ();
            }
        });
    }

    private void ᐝ() {
        findViewById(j.ˋᐠ).setOnClickListener(new evx(this) {
            final /* synthetic */ ThirdAppZoneActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void ˋ(View view) {
                this.ॱ.ᐝॱ();
            }
        });
    }

    private void ˏ(int i) {
        switch (i) {
            case -1:
                if (this.ॱˎ != null) {
                    this.ॱˎ.hide();
                }
                this.ॱᐝ.setVisibility(8);
                return;
            case 0:
                if (this.ʾ == 3) {
                    if (this.ॱˎ != null) {
                        this.ॱˎ.hide();
                    }
                    this.ॱᐝ.setVisibility(8);
                    return;
                } else if (azc.ˎ().ॱ() >= 17) {
                    this.ॱᐝ.setVisibility(8);
                    return;
                } else if (getActionBar() != null) {
                    getActionBar().hide();
                    return;
                } else {
                    return;
                }
            case 1:
                evd.ˏ(getWindow());
                ayw.ˏ(this, 16908290, null, false);
                if (this.ॱˎ != null) {
                    this.ॱˎ.hide();
                }
                this.ॱᐝ.setVisibility(8);
                this.ॱˋ.setVisibility(0);
                return;
            default:
                return;
        }
    }

    public void ˋ(int i, int i2) {
        if (this.ॱˋ != null) {
            this.ॱˋ.ˋ(i, i2);
        }
    }

    public void ॱ(int i, CSSStyleSheet cSSStyleSheet, String str) {
        this.ʻॱ = i;
        if (Logger.ˎ()) {
            Logger.ˏ("ThirdAppZoneActivity", "onInitActionBar: style=" + i + "; contentType=" + this.ʾ);
        }
        if (cSSStyleSheet == null) {
            cSSStyleSheet = CSSStyleSheet.parse(this.ˏॱ);
        }
        if (i != 1) {
            this.ʻॱ = 0;
            getWindow().getDecorView().setBackgroundColor(getResources().getColor(c.ॱˎ));
            if (this.ʾ != 3) {
                if (azc.ˎ().ॱ() >= 17) {
                    if (getActionBar() != null) {
                        getActionBar().show();
                        return;
                    }
                    return;
                } else if (this.ॱᐝ != null) {
                    this.ॱᐝ.setVisibility(0);
                    return;
                } else {
                    return;
                }
            } else if (this.ॱˋ != null) {
                this.ॱˋ.setBgColor(getResources().getColor(c.ॱˎ));
            }
        }
        evd.ˏ(getWindow());
        ayw.ˏ(this, 16908290, null, false);
        View findViewById = getWindow().getDecorView().findViewById(16908335);
        if (findViewById != null) {
            findViewById.setVisibility(8);
        }
        if (this.ॱˋ != null) {
            this.ॱˋ.setVisibility(0);
            this.ॱˋ.setActionbarClickListener(this);
        }
        ˏ(cSSStyleSheet, str);
    }

    private void ˏ(CSSStyleSheet cSSStyleSheet, String str) {
        if (cSSStyleSheet == null) {
            cSSStyleSheet = CSSStyleSheet.parse(this.ˏॱ);
        }
        if (cSSStyleSheet == null || str == null) {
            this.ʻॱ = 0;
            return;
        }
        CSSRule rule = new CSSSelector(str).getRule(cSSStyleSheet.getRootRule());
        if (rule != null) {
            CSSRule rule2 = new CSSSelector(".body").getRule(rule);
            if (rule2 != null) {
                CSSView.wrap(getWindow().getDecorView(), rule2).render(false);
            }
            if (this.ॱˋ != null) {
                CSSView.wrap(this.ॱˋ, rule).render();
            }
        }
    }

    public void ˎ(int i) {
    }

    public void setTitle(CharSequence charSequence) {
        if (TextUtils.isEmpty(charSequence)) {
            charSequence = getString(n.ॱـ);
        }
        if ((this.ʻॱ == 1 || this.ʾ == 3) && this.ॱˋ != null) {
            this.ॱˋ.setTitle(charSequence);
        } else if (azc.ˎ().ॱ() >= 17) {
            this.ॱˎ.setTitle(charSequence);
        } else {
            this.ᐝॱ.setText(charSequence);
        }
    }

    public void ᐝॱ() {
        finish();
    }

    public void ʼॱ() {
        djf.ˋ(this, this.ͺ, null);
    }

    public void ˊˋ() {
    }

    private void ͺ() {
        if (this.ॱˊ) {
            unregisterReceiver(this.ʼॱ);
        }
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putInt("AppDetailActivity.isimmer", this.ʻॱ);
        bundle.putInt("AppDetailActivity.scrolly", this.ʿ);
        bundle.putInt("AppDetailActivity.headheight", this.ʽॱ);
        bundle.putInt("AppDetailActivity.bgcolor", this.ˈ);
        bundle.putInt("AppDetailActivity.contenttype", this.ʾ);
        Object ˏ = epr.ˎ().ˏ();
        if (!TextUtils.isEmpty(ˏ)) {
            bundle.putString("ThirdAppZoneActivity.Card.ThirdId", ˏ);
            bundle.putString("ThirdAppZoneActivity.Card.URI", this.ˊॱ);
            super.onSaveInstanceState(bundle);
        }
    }

    public void onDestroy() {
        cwv.ॱ().ˎ(null);
        epr.ˎ().ˎ(null);
        ͺ();
        super.onDestroy();
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (4 == keyEvent.getKeyCode()) {
            finish();
        }
        return false;
    }

    private void ॱˊ() {
        List<RunningTaskInfo> runningTasks = ((ActivityManager) getSystemService("activity")).getRunningTasks(1000);
        if (!CollectCheck.isEmpty((List) runningTasks)) {
            for (RunningTaskInfo runningTaskInfo : runningTasks) {
                if ("com.huawei.appmarket.MarketActivity".equals(runningTaskInfo.baseActivity.getClassName())) {
                    Intent intent = new Intent();
                    intent.setAction("android.intent.action.MAIN");
                    intent.addCategory("android.intent.category.HOME");
                    startActivity(intent);
                    break;
                }
            }
        }
        finish();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != 16908332) {
            return super.onOptionsItemSelected(menuItem);
        }
        finish();
        return true;
    }

    public void ˎ(TaskFragment taskFragment, List<cvt> list) {
        SafeBundle safeBundle = new SafeBundle(taskFragment.ˊॱ());
        list.add(cfv.ˎ(safeBundle.getString(RemoteBuoyAction.REMOTE_BUOY_URI), safeBundle.getString("trace_id"), dgm.ˎ((Activity) this), 1));
    }

    public boolean ˋ(TaskFragment taskFragment, b bVar) {
        Fragment fragment = null;
        if (!ˊ(taskFragment, bVar)) {
            return false;
        }
        DetailResponse detailResponse = (DetailResponse) bVar.ˋ;
        ˋ(detailResponse);
        switch (detailResponse.ॱॱ()) {
            case 1:
            case 2:
                if (detailResponse.ˎ() == null || detailResponse.ˎ().size() <= 0) {
                    this.ʻॱ = detailResponse.ˊॱ();
                    if (epw.ˏ()) {
                        this.ʻॱ = 0;
                    }
                    SafeBundle safeBundle = new SafeBundle(taskFragment.ˊॱ());
                    String string = safeBundle.getString(RemoteBuoyAction.REMOTE_BUOY_URI);
                    this.ͺ = safeBundle.getString("trace_id");
                    AppListFragmentRequest appListFragmentRequest = new AppListFragmentRequest();
                    appListFragmentRequest.ˋ(string);
                    appListFragmentRequest.ˊ(this.ͺ);
                    appListFragmentRequest.ॱ(1);
                    appListFragmentRequest.ˊ(detailResponse.ʼॱ());
                    cjo appListFragmentProtocol = new AppListFragmentProtocol();
                    appListFragmentRequest.ˏ(this.ʻॱ);
                    String ˊ = ˊ(detailResponse);
                    if (!(detailResponse.ॱˎ() == null || ˊ == null)) {
                        appListFragmentRequest.ᐝ(detailResponse.ॱˎ().toString());
                        appListFragmentRequest.ʼ(ˊ);
                    }
                    appListFragmentProtocol.ˏ(appListFragmentRequest);
                    setTitle(detailResponse.ˋ());
                    ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("applist.fragment", appListFragmentProtocol));
                    if (!(contractFragment == null || contractFragment.ˊ(cin.class) == null)) {
                        ((cin) contractFragment).ॱ(bVar);
                        break;
                    }
                }
            case 3:
                this.ʾ = 3;
                fragment = ˎ(taskFragment, bVar);
                break;
        }
        ˋ(fragment);
        ˏ(detailResponse);
        return true;
    }

    private String ˊ(DetailResponse detailResponse) {
        List ʻॱ = detailResponse.ʻॱ();
        if (CollectCheck.isEmpty(ʻॱ)) {
            return null;
        }
        if (detailResponse.ॱˎ() != null) {
            this.ˏॱ = detailResponse.ॱˎ().toString();
        }
        return ((Layout) ʻॱ.get(0)).ˏ();
    }

    private ContractFragment ˎ(TaskFragment taskFragment, b bVar) {
        drr o_drr = new drr();
        drr.ˊ(o_drr, bVar.ˊ, bVar.ˋ);
        this.ͺ = new SafeBundle(taskFragment.ˊॱ()).getString("trace_id");
        DetailResponse detailResponse = (DetailResponse) bVar.ˋ;
        if (detailResponse.ॱ() == 0) {
            o_drr.ˏ(false);
        } else {
            o_drr.ˏ(true);
        }
        DetailHeadBean ˋ = o_drr.ˋ();
        DetailHiddenBean ᐝ = o_drr.ᐝ();
        if (ˋ == null || ᐝ == null || CollectCheck.isEmpty(o_drr.ʽ()) || (ᐝ.ͺˏ() == null && ᐝ.ॱ() == 0)) {
            return null;
        }
        cjo appDetailFragmentProtocol = new AppDetailFragmentProtocol();
        Request request = new Request();
        request.ॱ(((cfv) bVar.ˊ).ˎ());
        request.ˏ(detailResponse.ˋ());
        request.ˊ(ˋ);
        request.ˋ(ᐝ, dgm.ˎ((Activity) this));
        request.ˋ(o_drr.ʽ());
        String ˊ = ˊ(detailResponse);
        if (!(detailResponse.ॱˎ() == null || ˊ == null)) {
            request.ˋ(detailResponse.ॱˎ().toString());
            request.ˊ(ˊ);
        }
        request.ˏ(detailResponse.ˊॱ());
        this.ʻॱ = detailResponse.ˊॱ();
        if (epw.ˏ()) {
            this.ʻॱ = 0;
        }
        appDetailFragmentProtocol.ˋ(request);
        ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm("appdetail.fragment", appDetailFragmentProtocol));
        drt o_drt = (drt) contractFragment.ˊ(drt.class);
        if (o_drt == null) {
            return contractFragment;
        }
        o_drt.ˋ(o_drr);
        o_drt.ॱ(bVar);
        return contractFragment;
    }

    private void ˋ(Fragment fragment) {
        if (fragment != null) {
            FragmentTransaction ˊ = ˏॱ().ˊ();
            ˊ.ˏ(j.ˋˊ, fragment);
            ˊ.ˋ();
        } else if (!isFinishing()) {
            finish();
        }
    }

    private void ˏ(DetailResponse<?> detailResponse) {
        if (detailResponse.ʽ() != null) {
            this.ˋॱ = detailResponse.ʽ();
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(dvq.ˊ());
            intentFilter.addAction(dvq.ˏ());
            intentFilter.addAction("android.intent.action.CLOSE_SYSTEM_DIALOGS");
            registerReceiver(this.ʼॱ, intentFilter);
            this.ॱˊ = true;
        }
    }

    private boolean ˊ(TaskFragment taskFragment, b bVar) {
        if (bVar.ˋ.getResponseCode() == 0) {
            return true;
        }
        if (taskFragment != null) {
            cir o_cir = (cir) taskFragment.ˊ(cir.class);
            if (o_cir != null) {
                o_cir.ॱ(bVar.ˋ.getResponseCode(), true);
            }
        }
        return false;
    }

    public void onResume() {
        super.onResume();
        dgh.ˏ(getClass().getCanonicalName(), ˊॱ());
    }

    public void onPause() {
        super.onPause();
        dgh.ॱ(getClass().getCanonicalName(), ˊॱ());
    }

    private LinkedHashMap ˊॱ() {
        LinkedHashMap linkedHashMap = new LinkedHashMap(3);
        if (!dof.ॱ(this.ͺ)) {
            linkedHashMap.put("third_id", this.ͺ);
        }
        if (!dof.ॱ(this.ˊॱ)) {
            linkedHashMap.put("page_id", this.ˊॱ);
        }
        linkedHashMap.put("service_type", Integer.valueOf(dgm.ˎ((Activity) this)));
        return linkedHashMap;
    }
}
